#include "StdAfx.h"
#include "Engine.h"
#include "GraphicDevice.h"
#include "Messenger.h"
#include <iostream>
#include "TimerController.h"
#include "WindowSetup.h"
#include "XmlConfigLoader.h"

#define ENGINE_CONFIG "config\\engine.xml"

BEGIN_XML_CONFIG_LOADER(Engine)
END_XML_CONFIG_LOADER

Engine::Engine(void) : GameObject(ClassEngine), XmlConfigLoader(ENGINE_CONFIG)
{
}

Engine::~Engine(void)
{
	DeviceManager::GetInstance()->UninitAllDevices();
	DeviceManager::GetInstance()->RemoveAll();
}

HRESULT Engine::Init(void)
{
	HRESULT hr;

	CHECKHR(ReadConfiguration());

	_WindowSetup.Init();
	Messenger::GetInstance()->Connect(this);

	// Messenger erstellen
	shared_ptr<GraphicDevice> gd(new GraphicDevice());
	DeviceManager::GetInstance()->Add(gd);
	hr = DeviceManager::GetInstance()->InitAllDevices();
	ASSERT(hr == S_OK);

	return S_OK;
}

HRESULT Engine::Uninit(void)
{
	HRESULT hr;
	CHECKHR(DeviceManager::GetInstance()->UninitAllDevices());


	return S_OK;
}

void Engine::OnSignal(GameObject * from, Sgn::Code code)
{
}

void Engine::OnTimer(UINT id)
{
}

void Engine::Loop(void)
{
	_WindowSetup.Loop();
}


